package com.web.daoimpl;

import com.web.entity.Teacher;
import com.web.dao.TeacherDao;
import com.web.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * TeacherDaoImpl 是teacherdao接口的实现类，包含了teacher表相关数据库操作的实现代码
 * @author 12270
 */
public class TeacherDaoImpl extends BaseDaoImpl implements TeacherDao{

    @Override
    public int update(Teacher t) {
        return excuteUpdate("update teachers set Tname=?,Tstatus=?,CourseID=?,ClassID=? where Tid=?",
                t.getTname(),
                t.getTstatus(),
                t.getCourseID(),
                t.getClassID(),
                t.getTid());
    }

    @Override
    public Teacher getOneByTid(String Tid) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        Teacher t = null;

        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select * from teachers where Tid=?");
            ps.setString(1, Tid);
            rs = ps.executeQuery();
           if (rs.next()) {
                return new Teacher(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6));
            } 
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return t;        
    }

    @Override
    public int updateTpwd(Teacher t) {
        return excuteUpdate("update teachers set Tpwd=? where Tid=?",
                t.getTpwd(),
                t.getTid());
    }
    }
    
